package com.usian.ai.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.usian.ai.common.Result;
import com.usian.ai.mapper.JobMapper;
import com.usian.ai.pojo.Job;
import com.usian.ai.pojo.vo.JobReqVo;
import com.usian.ai.pojo.vo.PageVo;
import com.usian.ai.service.JobService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 12 06 11 36
 **/

@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, Job>
implements JobService {

   @Autowired
   JobMapper jobMapper;


    @Override
    public Result listJob(PageVo pageVo) {
//        Page<Job> jobPage = new Page<>(pageVo.getPageNumber(), pageVo.getPageSize());
//        Page<Job> jobPage1 = this.baseMapper.selectPage(jobPage, null);

        //连接查询
        //1：定义sql
        //2：mybatis xml
        PageHelper.startPage(pageVo.getPageNumber(),pageVo.getPageSize());

        List list = jobMapper.selectJob();

        PageInfo pageInfo = new PageInfo(list);

        return Result.ok(pageInfo);

    }

    @Override
    public Result addJob(JobReqVo jobReqVo) {

        Job job = new Job();
        BeanUtils.copyProperties(jobReqVo,job);
        job.setCreateTime(LocalDateTime.now());
        job.setUpdatedTime(LocalDateTime.now());

        int insert = this.baseMapper.insert(job);

        return Result.ok(insert);
    }
}
